﻿
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace WebAppDemo.Classes
{
    [System.Serializable]
    public class Person
    {
        public int Age { get; set; }
        public string Name { get; set; }
        public int Amount { get; set; }

        public Person()
        {
        }

        public Person(string name)
        {
            Name = name;
            Amount = 100;
        }

        public void Withdraw(int amount)
        {
            Amount = -amount;
        }

        public Person Clone()
        {
            using (var ms = new MemoryStream())
            {
                var bf = new BinaryFormatter();
                bf.Serialize(ms, this);

                var bf2 = new BinaryFormatter();
                ms.Seek(0, SeekOrigin.Begin);
                var p = bf2.Deserialize(ms);
                return (Person)p;
            }
        }
    }
}
